    //
//  RootNavigationController.m
//  jobClient
//
//  Created by 一览ios on 16/7/15.
//  Copyright © 2016年 YL1001. All rights reserved.
//

#import "RootNavigationController.h"

@interface RootNavigationController ()

@end

@implementation RootNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configUI];
}

-(void)configUI{
    
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];

//    if(@available(iOS 13.0, *)) {
//        UINavigationBarAppearance *appearance = [UINavigationBarAppearance new];
//        [appearance configureWithOpaqueBackground];
//        appearance.backgroundImage = UIImage.new;
//        appearance.backgroundColor = EL_NavBarTintColor;
//        appearance.shadowImage = UIImage.new;
//        appearance.shadowColor = UIColor.clearColor;
//
////        [[UINavigationBar appearance] setScrollEdgeAppearance:appearance];
//        [[UINavigationBar appearance] setStandardAppearance:appearance];
//
//    }
    
    //导航栏背景色
    UIColor *navBarColor = [UIColor whiteColor];
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *appearance = [[UINavigationBarAppearance alloc] init];
        appearance.backgroundColor = navBarColor;
        appearance.backgroundEffect = nil;
        appearance.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor]};
        appearance.shadowColor = UIColor.clearColor;
        appearance.shadowImage = [self imageWithColor:UIColor.clearColor];
        self.navigationBar.scrollEdgeAppearance = appearance;
        self.navigationBar.standardAppearance = appearance;
        
    }else{
        [self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:UIColor.whiteColor] forBarMetrics:UIBarMetricsDefault];
        //设置导航栏文字颜色
        [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    }
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

    
    
//    [[UINavigationBar appearance] setBackgroundImage:[self imageWithColor:UIColor.whiteColor] forBarMetrics:UIBarMetricsDefault];//[self imageWithColor:UIColor.whiteColor]
    [[UINavigationBar appearance] setShadowImage:[UIImage new]];//[self imageWithColor:UIColorFromRGB(0xF3F3FC)]


    self.navigationBar.translucent = NO;//    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.navigationBar.barTintColor = EL_NavBarTintColor;

    //设置导航条字体
    NSShadow *shadow = [[NSShadow alloc]init];
    shadow.shadowColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
    NSMutableDictionary *titleDict = [NSMutableDictionary dictionaryWithObject:EL_NavBarTitleColor   forKey:NSForegroundColorAttributeName];
    [titleDict setObject:EL_NavBarTitleFont forKey:NSFontAttributeName];
    [titleDict setObject:shadow forKey:NSShadowAttributeName];
    [[UINavigationBar appearance] setTitleTextAttributes:titleDict];

}
                                           
-(UIImage*)imageWithColor:(UIColor*) color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return theImage;
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    return [super pushViewController:viewController animated:animated];
}

-(NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated
 {

         if (animated) {
  
         UIViewController *popController = self.viewControllers.lastObject;
         popController.hidesBottomBarWhenPushed = NO;
        }
        return [super popToRootViewControllerAnimated:animated];
}



@end
